package DBLayer;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import ExceptionLayer.CustomException;
import ModelLayer.Treatment;

public class DBTreatmentRel implements IFDBTreatmentRel
{
	private Connection con;

	public DBTreatmentRel()
	{
		con = DBConnection.getInstance().getDBcon();
	}

	public void insertTreatRel(Treatment parent, Treatment sub) throws CustomException
	{
		String query = "INSERT INTO TreatmentRel (TreatmentID, SubTreatID) VALUES (?, ?)";
		
		
		try
		{
			PreparedStatement pstmtRel = con.prepareStatement(query);
			pstmtRel.setInt(1, parent.getId());
			pstmtRel.setInt(2, sub.getId());
			pstmtRel.executeUpdate();
		}
		catch(SQLException sqlEx)
		{
			throw new CustomException("Error inserting treatment relation");
		}
	}
}
